package cn.edu.njuit.server.ugcnote.ugcnoteserver.repository;

import cn.edu.njuit.server.ugcnote.ugcnoteserver.entity.NoteInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface NoteInfoRepository extends JpaRepository<NoteInfo, Long> {
    @Query("select a from NoteInfo a where a.noteStatus='1' and (0L=?1 or a.typeInfo.id=?1 )" +
            " order by a.publishTime desc")
    Page<NoteInfo> findPublishedNotes(Long typeId,Pageable pageable);


    @Query("select a from NoteInfo a,UserInfo b where a.userInfo.id=b.id and a.noteStatus='1' and b.userName=?1 " +
            " order by a.publishTime desc")
    Page<NoteInfo> findMyNotes(String login,Pageable pageable);
}
